package com.hc.window.textFileManageView;

import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;

import com.hc.bean.FileBean;
import com.hc.util.CommonData;
import com.hc.util.CommonView;
import com.hc.util.ToDoFileUtil;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.border.TitledBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import javax.swing.JSeparator;



public class TodoItemPanel extends JPanel{
	public JPanel panel;
	
	public  JPanel todoItemHeandItemPanel;
	
	public  List<ItemHeadLabel> ItemHeadLabelList = new ArrayList<ItemHeadLabel>();
	
	public TodoItemPanel() {
	
		

		
		
		setLayout(new BorderLayout(0, 0));
		
		TodoItemHeadPanel headPanel = new TodoItemHeadPanel();
		
		
		todoItemHeandItemPanel  = new JPanel();
	


		FlowLayout flowLayout = (FlowLayout) todoItemHeandItemPanel.getLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		todoItemHeandItemPanel.setPreferredSize(new Dimension(500, 30));
		JPanel headPanelItem = new JPanel(); 
		headPanelItem.setLayout(new BorderLayout(0, 0));
		
		headPanelItem.add(headPanel, BorderLayout.NORTH);
		headPanelItem.add(todoItemHeandItemPanel,  BorderLayout.SOUTH);
		
		add(headPanelItem, BorderLayout.NORTH);
		

		
	
		
		JSeparator separator = new JSeparator();
		headPanelItem.add(separator, BorderLayout.CENTER);
		
		panel= new JPanel();
		add(new JScrollPane(panel), BorderLayout.CENTER);
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

		
		ItemHeadLabel homeLabel = new ItemHeadLabel(" > HOME ", ToDoFileUtil.FILEPATH);
		ItemHeadLabelList.add(homeLabel);
		todoItemHeandItemPanel.add(homeLabel);
		
		
		refreshView(ToDoFileUtil.FILEPATH);
		
		
	}

	public void refreshView(String filePath){
		
		
		panel.removeAll();
		List<FileBean> files = ToDoFileUtil.getTodoFileList(filePath);
		
		for(int i =(files.size()-1);i > -1;i--){
			FileBean bean = files.get(i);
			
			ToDoItem to = new ToDoItem();
			to.setFileType(bean.getFileType());
			to.setTempValue(bean.getCotent30char());
			to.setStr(bean.getName());
			to.setFilePath(bean.getFilePath());
			
			panel.add(to);
		}
		
		int num = 	CommonData.window_hight  - 250 - files.size()*50;
		
	
			
			
		if (CommonData.nowFilePath.equals(ToDoFileUtil.FILEPATH)) {
			if (num > 10) {
				JPanel tempPanel = new JPanel();
				tempPanel.setPreferredSize(new Dimension(600, num));
				panel.add(tempPanel);
			}

		} else {

			DelFolderPnel delPanel = new DelFolderPnel();
			if (num > 60) {
				num = num - 50;
				JPanel tempPanel = new JPanel();
				tempPanel.setPreferredSize(new Dimension(600, num));
				panel.add(tempPanel);
				panel.add(delPanel);
			} else {
				panel.add(delPanel);
			}
		}
		
		
		panel.setVisible(false);
		panel.setVisible(true);
	}

	public void addItemHead(ItemHeadLabel itemHeadLabel){
		
		ItemHeadLabelList.add(itemHeadLabel);
		todoItemHeandItemPanel.add(itemHeadLabel);
		todoItemHeandItemPanel.setVisible(false);
		todoItemHeandItemPanel.setVisible(true);
	}
	public void refreshViewItemHead(){
		
		todoItemHeandItemPanel.removeAll();
		
		
		for(int i = 0 ; i <ItemHeadLabelList.size();i++){
			
			todoItemHeandItemPanel.add(ItemHeadLabelList.get(i));
		}
		
		
		todoItemHeandItemPanel.setVisible(false);
		todoItemHeandItemPanel.setVisible(true);
	}
}
